<template>
  <div> <van-empty v-if="list.length==0" description="暂无地址" />
   <!-- 
    v-model :当前选中地址的 id
    list	地址列表	Address[{id:"",name:"",tel:"",address:"",isDefault:true}]
    default-tag-text: 默认显示的文本
    -->
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    /></div>
</template>

<script>
import {reqaddresslist} from '../../http/http'
export default {
  data(){
    return {
      chosenAddressId:'1',
      list:[],
    }
  },
  mounted(){

    this.chosenAddressId = Number(this.$route.query.id)
    
    reqaddresslist({
      uid:JSON.parse(localStorage.getItem("isLogin")).uid
    }).then(res=>{
      let arr = res.data.list?res.data.list:[]
      this.list = arr.map(item=>{
        return {
          id:item.id,
          name:item.username,
          tel:item.userphone,
          address:item.location + item.useraddress,
          isDefault:item.status == 1
        }
      })
    })
  },
  methods:{
    onAdd(){
      this.$router.push('/a-add')
    },
    onEdit(item,index) {
      console.log('编辑地址:' + index,item);
      
    },
    //点了编辑
    onEdit(item,index) {
      this.$router.replace('/a-add?id=' +item.id)
    },
    select(item){
      this.$router.push('/order?addressId'+item.id)
    }
  },


}
</script>

<style>

</style>